package com.titanrise.crm.environment.orm;

import com.titanrise.crm.environment.annotation.*;

import java.lang.reflect.*;

@Component
public class MapperProxy implements InvocationHandler {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (method.getAnnotation(Select.class) != null) {
            return MapperProxyUtil.executeSelect(method, args);
        } else if (method.getAnnotation(Update.class) != null) {
            return MapperProxyUtil.executeUpdate(method, args);
        } else if (method.getAnnotation(Insert.class) != null) {
            return MapperProxyUtil.executeInsert(method, args);
        } else if (method.getAnnotation(Delete.class) != null) {
            return MapperProxyUtil.executeDelete(method, args);
        } else if (method.getName().equals("toString")) {
            return "MapperProxy";
        } else {
            return null;
        }
    }
}
